package com.gba.mark.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gba.mark.exam.entity.ExamPaper;
import com.gba.mark.exam.entity.ExamQuestions;
import com.gba.mark.exam.service.ExamPaperService;
import com.gba.mark.util.ResponseUtil;
import com.qigetech.utils.resultbundle.ResultBundle;
import com.qigetech.utils.resultbundle.ResultBundleBuilder;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Queue;

@RestController
@RequestMapping ("/exam/paper")
public class ExamPaperController {

    @Autowired
    private ExamPaperService examPaperService;

    @Autowired
    private ResultBundleBuilder resultBundleBuilder;

    /**
     * 新建并保存一份试卷
     */
    @PostMapping("/savePaper")
    public ResponseUtil<Integer> update(@RequestBody List<ExamQuestions> questions,
                                        @RequestParam int group_id){
        return new ResponseUtil<>(HttpStatus.OK, examPaperService.savePaper(questions, group_id));
    }

    /**
     * 删除一份试卷
     */
    @DeleteMapping("/{id}")
    public ResultBundle<Boolean> delete(@PathVariable("id") int id) {
        return resultBundleBuilder.bundle("", () -> examPaperService.removeById(id));
    }

    @GetMapping("/{id}")
    public ResultBundle<ExamPaper> queryById(@PathVariable("id") int id) {
        return resultBundleBuilder.bundle("", () -> examPaperService.getById(id));
    }

    @GetMapping("/list")
    public ResultBundle<IPage<ExamPaper>> list(@RequestParam(name = "pageNum", defaultValue = "0") int pageNum,
                                          @RequestParam(name = "pageSize", defaultValue = "20") int pageSize) {// 1 10
        return resultBundleBuilder.bundle("", () ->
                examPaperService.page(new Page<>(pageNum, pageSize)));
    }

//    /*
//    查询用户的试卷
//     */
//    @GetMapping("/{id}")
//    public  ResultBundle<ExamPaper> selectedPaper (@PathVariable ("id") int id){
//        return resultBundleBuilder.bundle("",() -> examPaperService.getById(id));
//    }
//

 }
